package com.day01_Array;

import java.util.Arrays;

/**
 * @ClassName: QuickSort
 * @Author: zw
 * @Description: 出百万拳，行万里路；
 * @Create 2024/6/23-10:45
 * @Version 1.0
 */
public class QuickSort {
    public static void main(String[] args) {
        test();
        // 测试以下Array api
        boolean isEquals = Arrays.equals(new int[]{1,2,3,4,5}, new int[]{1,2,3,4,5});
        System.out.println("相等：" + isEquals);
        boolean isEqualss = Arrays.equals(new byte[]{'h','e'}, new byte[]{'h','e'});
        System.out.println("相等：" + isEqualss);

    }
    public static void test() {
        int[] nums = {32,45,114,557,34,2};
        quickSort(nums, 0, nums.length - 1);
        for (int i : nums) {
            System.out.println(i);
        }
    }
    public static void quickSort(int[] nums, int start, int end) {
        if (start < end) {
            int base = nums[start];
            int l = start;
            int r = end;
            while (l < r) {
                while (l < r && nums[r] >= base) {
                    r--;
                }
                nums[l] = nums[r];
                while (l < r && nums[l] <= base) {
                    l++;
                }
                nums[r] = nums[l];
            }
            nums[l] = base;
            quickSort(nums, start, l - 1);
            quickSort(nums, l+1, end);
        }


    }
}
